import torch

# 假设你有一个张量 tensor
tensor = torch.tensor([[1, 2, 3],
                       [4, 5, 6],
                       [7, 8, 9]])

one_tensor=torch.ones_like(tensor)
#one_tensor[:, 2] = tensor[:, 2]
#one_tensor[:, 2].copy_(tensor[:, 2])
#print(one_tensor)
one_tensor.index_select(1, torch.LongTensor([2])).copy_(tensor.index_select(1, torch.LongTensor([2])))
print(one_tensor)

# 提取第 col_index 列
col_index = 1
extracted_col = tensor[:, col_index]

# 重复提取的列 num_repeats 次
num_repeats = 3
repeated_col = extracted_col.unsqueeze(1).repeat(1, num_repeats)

# 打印结果
print("原始张量:")
print(tensor)
print("\n提取的列:")
print(extracted_col)
print("\n重复后的列:")
print(repeated_col)
